package com.example.cookbook.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.cookbook.R;
import com.example.cookbook.activity.RecipeDetailActivity;
import com.example.cookbook.bean.RecipeBean;

import java.util.List;

import androidx.recyclerview.widget.RecyclerView;

public class RecipeSearchAdapter extends RecyclerView.Adapter<RecipeSearchAdapter.ViewHolder> {
    private Context wcontext;
    private List<RecipeBean> arrlist6;
    //创建构造方法
    public RecipeSearchAdapter(Context wcontext, List<RecipeBean> arrlist6) {
        this.wcontext = wcontext;
        this.arrlist6 = arrlist6;
    }
    @Override
    public RecipeSearchAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int i) {
        View view= LayoutInflater.from(wcontext).inflate(R.layout.recy_cx_item,parent,false);
        ViewHolder myholder=new ViewHolder(view);
        return myholder;
    }

    @Override
    public void onBindViewHolder(RecipeSearchAdapter.ViewHolder myholder, int i) {
        final RecipeBean courseInfo= arrlist6.get(i);
        myholder.cx_name.setText(courseInfo.getCpName());
        myholder.cx_des.setText(courseInfo.getDes());
        Glide.with(wcontext).load(courseInfo.getSmallImg()).into(myholder.cx_img);
        myholder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(wcontext, RecipeDetailActivity.class);
                intent.putExtra("data",courseInfo);
                wcontext.startActivity(intent);
            }
        });
    }
    @Override
    public int getItemCount() {
        return arrlist6.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView cx_img;
        TextView cx_name,cx_des;
        public ViewHolder(View itemView) {
            super(itemView);
            cx_img=itemView.findViewById(R.id.cx_img);
            cx_name=itemView.findViewById(R.id.cx_name);
            cx_des=itemView.findViewById(R.id.cx_des);
        }
    }

}